package com.zjxf.controller;

import com.alibaba.fastjson.JSONObject;
import com.zjxf.base.bean.po.PmsAsProduct;
import com.zjxf.base.bean.ro.RoPmsAsProduct;
import com.zjxf.base.bean.vo.VoPmsAsProduct;
import com.zjxf.base.common.JSONResponse;
import com.zjxf.base.common.OperationException;
import com.zjxf.base.common.SysConst;
import com.zjxf.controller.common.BaseController;
import com.zjxf.service.PmsAsProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * 农副产品
 *
 * @author ZhangWei
 * @date 2021/4/6/006 15:59
 */
@Validated
@RestController
@AllArgsConstructor
@Api(tags = "农副产品")
@RequestMapping("/pmsAsProduct/")
public class PmsAsProductController extends BaseController {

    private final PmsAsProductService pmsAsProductService;

    @ApiOperation(value = "删除")
    @PostMapping("delete")
    public JSONResponse delete(@NotNull(message = "请填写产品id") @RequestParam Long id) throws OperationException {
        pmsAsProductService.delete(id);
        return JSONResponse.success(SysConst.SUCCESS);
    }

    @ApiOperation(value = "回显")
    @PostMapping("get")
    public JSONResponse get(@NotNull(message = "请填写产品id") @RequestParam Long id) throws OperationException {
        PmsAsProduct pmsAsProduct = pmsAsProductService.getEntity(id);
        RoPmsAsProduct.Details details = pmsAsProductService.getEntityRo(pmsAsProduct);
        return JSONResponse.success(details);
    }

    @ApiOperation(value = "分页")
    @PostMapping("page")
    public JSONResponse page(@Valid @RequestBody VoPmsAsProduct.filter filter) {
        Page<PmsAsProduct> pmsAsProductPage = pmsAsProductService.page(filter);
        JSONObject jsonData = pmsAsProductService.sellerPageRo(pmsAsProductPage);
        return JSONResponse.success(jsonData);
    }

    @ApiOperation(value = "审核")
    @PostMapping("verify")
    public JSONResponse verify(@Valid @RequestBody VoPmsAsProduct.verify verify) throws OperationException {
        pmsAsProductService.verify(verify);
        return JSONResponse.success(SysConst.SUCCESS);
    }

}
